**************************************************************************
*																		*
*			Campaign Panel Book Chapter 5 - Fixed-Effects Regression Turnout								*
*																		*
*************************************************************************

cd "${path}\Reproducible Do-Files\Chapter 5\Data"
use longformat09.dta, clear
xtset lfdn welle


local kommunikation watcheddebate gesprhin pk_gesamtino pr_bild i_nupol pr_paper pr_andz tv_oeff tv_privat m_gesamti
local attitudes wkampfint intefficacy extefficacy zufr entfremda indiff
local time w2 w3 w4 w5 w6 w7

sum `kommunikation' `attitudes'

* Only obsevations (wave) with valid measures in both IV-blocks
egen miss = rowmiss(wwbt `kommunikation' `attitudes')

fre miss
drop if miss~=0
fre miss

* Delete respondents with only a single valid combination of IV and DV
* (combination valid at only one point in time)
					
bysort lfdn: egen count = count(miss)	//Count observations per respondent
fre count	

list lfdn welle miss count in 1/100, sepby(lfdn)

drop if count==1
						
* Variable indicating whether a respondent has 7 valid observations
bysort lfdn: egen total = total(allvalid)

* Estimate profit for number of cases
est clear
eststo: xtreg wwbt `attitudes' `time' if wwbttyp!=0, fe
eststo: xtreg wwbt `attitudes' `time' if wwbttyp!=0 & (total==7 | (total==6 & teil_w1==0)), fe


*------------------------------------------
* Table 44: Comparison Stable and Instable
*------------------------------------------

cd "${path}\Reproducible Do-Files\Chapter 5"

* Stables	
est clear
eststo: estpost sum wwbt watcheddebate if wwbttyp==0 & welle==7
eststo: estpost sum polint nopid wkampfint intefficacy extefficacy ///
	indiff entfremda if wwbttyp==0 & welle==2



* Instables
eststo: estpost sum wwbt watcheddebate if wwbttyp~=0 & welle==7	
eststo: estpost sum polint nopid wkampfint intefficacy extefficacy ///
	indiff entfremda if wwbttyp~=0 & welle==2

	
esttab using "Stable vs. unstable 2009.rtf", cells(mean(fmt(2))) ///
	mtitles("stable" "stable" "FE-sample" "FE-sample")	///
	coeflabel(wwbt "% Turnout" watcheddebate "% TV Debate" ///
	polint "Mean political interest" ///
	nopid1 "% No PID" wkampfint "Mean campaign interest" ///
	intefficacy "Mean internal efficacy" ///
	extefficacy "Mean external efficacy" indiff "Mean indifference" ///
	entfremda  "Mean Alienation") replace

*Real number of observations for table 44

sum wwbt watcheddebate polint nopid wkampfint intefficacy extefficacy indiff entfremda if wwbttyp==0 & welle==1
	
sum wwbt watcheddebate polint nopid wkampfint intefficacy extefficacy indiff entfremda if wwbttyp~=0 & welle==1
*------------------------------------------------
* Tabel 45 direct and total effects
*------------------------------------------------	

est clear	
eststo: xtreg wwbt `attitudes' `time' if wwbttyp!=0, fe  
eststo: xtreg wwbt `kommunikation' `time' if wwbttyp!=0, fe  
eststo: xtreg wwbt `attitudes' `kommunikation' `time' if wwbttyp!=0, fe 
eststo: xtreg wwbt `attitudes' `kommunikation' `time', fe 


esttab using wbt2009.rtf, b(2) not title("Direct and total effects of campaign reception and participatory attitudes on turnout") ///
	mtitle("Total effect" "Total effect" "Direct effect" "Full Sample") nolz ///
	sca(N N_g r2) replace drop(_cons w2 w3 w4 w5 w6 w7) ///
	coeflabels(wkampfint "Interest in campaign" intefficacy "Internal efficacy" extefficacy "External efficacy" zufr "Satisfaction with democracy" entfremda "Alienation" indiff "Indifference" ///
	watcheddebate "TV-debate" gesprhin "Discussion" pk_gesamtino "Party contacts campaign" pr_bild "Bild" i_nupol "Internet political content" pr_paper "Quality newspaper" pr_andz "Other newspapers" ///
	tv_oeff "TV-news public" tv_privat "TV-news private" m_gesamti "Weekly magazines") ///
	note("Note: Models include wave dummies")

		
*------------------------------------------------
* Table 46 total effects, increasings and decreasings
*------------------------------------------------	
		
est clear
eststo: xtreg wwbt `attitudes' `time' if wwbttyp==1, fe 
eststo: xtreg wwbt `kommunikation' `time' if wwbttyp==1, fe  
eststo: xtreg wwbt `attitudes' `time' if wwbttyp==-1, fe 
eststo: xtreg wwbt `kommunikation' `time' if wwbttyp==-1, fe 

esttab using wbt2009.rtf, b(2) not title("Total effects of campaign reception and participatory attitudes on turnout by patterns of voting behavior") ///
	mtitle("Total effect" "Total effect" "Total effect" "Total effect") nolz ///
	sca(N N_g r2) append drop(_cons w2 w3 w4 w5 w6 w7) ///
	coeflabels(wkampfint "Interest in campaign" intefficacy "Internal efficacy" extefficacy "External efficacy" zufr "Satisfaction with democracy" entfremda "Alienation" indiff "Indifference" ///
	watcheddebate "TV-debate" gesprhin "Discussion" pk_gesamtino "Party contacts campaign" pr_bild "Bild" i_nupol "Internet political content" pr_paper "Quality newspaper" pr_andz "Other newspapers" ///
	tv_oeff "TV-news public" tv_privat "TV-news private" m_gesamti "Weekly magazines") ///
	note("Note: Models include wave dummies")

*------------------------------------------------
* Split political interest (table 47)
*------------------------------------------------	


est clear
foreach num of numlist -1 0 1 {
eststo: xtreg wwbt `attitudes' `time' if polintsplit==`num' & wwbttyp!=0, fe  
}
foreach num of numlist -1 0 1 {
eststo: xtreg wwbt `kommunikation' `time' if polintsplit==`num' & wwbttyp!=0, fe 
}
esttab using wbt2009.rtf, b(2) not ///
	title("Erklärung Wahlbeteiligung 2009. Modell 1: Einstellungen. Split by political interest") ///
	mtitle("Low" "Med." "High" "Low" "Med." "High")  nolz ///
	sca(N N_g r2) append drop(_cons w2 w3 w4 w5 w6 w7) ///
	coeflabels(wkampfint "Interest in campaign" intefficacy "Internal efficacy" extefficacy "External efficacy" zufr "Satisfaction with democracy" entfremda "Alienation" indiff "Indifference" ///
	watcheddebate "TV-debate" gesprhin "Discussion" pk_gesamtino "Party contacts campaign" pr_bild "Bild" i_nupol "Internet political content" pr_paper "Quality newspaper" pr_andz "Other newspapers" ///
	tv_oeff "TV-news public" tv_privat "TV-news private" m_gesamti "Weekly magazines") ///
	note("Note: Models include wave dummies")

*------------------------------------------------------------------
* Split party identification vs. no party identification (table 48)
*------------------------------------------------------------------

* Model 1: total effects attitudes
est clear
eststo: xtreg wwbt `attitudes' `time' if nopid==1 & wwbttyp!=0, fe	
eststo: xtreg wwbt `kommunikation' `time' if nopid==1 & wwbttyp!=0, fe 
eststo: xtreg wwbt `attitudes' `time' if nopid==0 & wwbttyp!=0, fe	
eststo: xtreg wwbt `kommunikation' `time' if nopid==0 & wwbttyp!=0, fe	

esttab using wbt2009.rtf, b(2) not ///
	title("Erklärung Wahlbeteiligung 2009. Modell 1: Einstellungen. Split by PID") ///
	mtitle("no PID" "no PID" "PID" "PID") nolz ///
	sca(N N_g r2) append drop(_cons w2 w3 w4 w5 w6 w7) ///
	coeflabels(wkampfint "Interest in campaign" intefficacy "Internal efficacy" extefficacy "External efficacy" zufr "Satisfaction with democracy" entfremda "Alienation" indiff "Indifference" ///
	watcheddebate "TV-debate" gesprhin "Discussion" pk_gesamtino "Party contacts campaign" pr_bild "Bild" i_nupol "Internet political content" pr_paper "Quality newspaper" pr_andz "Other newspapers" ///
	tv_oeff "TV-news public" tv_privat "TV-news private" m_gesamti "Weekly magazines") ///
	note("Note: Models include wave dummies")
	
